package org.ciallo.easytokencore.context;

import org.ciallo.easytokencore.context.model.EasyCookie;
import org.ciallo.easytokencore.context.model.EasyRequest;
import org.ciallo.easytokencore.context.model.EasyResponse;
import org.ciallo.easytokencore.context.model.EasyToken;

/**
 * Easy-Token 请求上下文封装类
 *
 * <p>核心功能：</p>
 * <ul>
 *   <li>封装当前请求的完整上下文信息</li>
 *   <li>提供统一的请求/响应/Cookie访问接口</li>
 *   <li>线程安全，每个请求独立实例</li>
 *   <li>支持在拦截器、控制器和服务层共享上下文</li>
 * </ul>
 *
 * <p>主要组件：</p>
 * <ul>
 *   <li>cookie: Cookie操作封装，支持链式调用</li>
 *   <li>request: 请求信息封装，包含headers/params/body</li>
 *   <li>response: 响应操作封装，支持状态码/headers设置</li>
 *   <li>token: JWT令牌封装，支持验证/刷新</li>
 * </ul>
 *
 * <p>使用示例：</p>
 * <pre>
 * {@code
 * // 1. 获取上下文
 * EasyContext context = EasyContextHolder.get();
 *
 * // 2. 请求处理示例
 * String userId = context.getToken().getPayload("userId");
 * String param = context.getRequest().getParam("page");
 *
 * // 3. 响应处理示例
 * context.getResponse()
 *     .setStatus(200)
 *     .addHeader("X-Version", "1.0");
 *
 * // 4. Cookie处理示例
 * context.getCookie()
 *     .set("token", "new-value")
 *     .setMaxAge(3600)
 *     .setHttpOnly(true);
 * }
 * </pre>
 *
 * <p>注意事项：</p>
 * <ul>
 *   <li>上下文实例与当前线程绑定，不要在异步任务中直接使用</li>
 *   <li>修改响应内容需要在控制器返回前完成</li>
 *   <li>token操作需要验证有效性</li>
 * </ul>
 *
 * @Description: Easy-Token 请求上下文核心类
 * @Author: Jukomu
 * @Package: org.ciallo.easytokencore.context
 * @Project: easy-token-demo
 * @Version: 1.1.0
 * @name: EasyContext
 * @Date: 2025-05-17
 * @Filename: EasyContext
 * @see EasyContextHolder
 * @see EasyRequest
 * @see EasyResponse
 * @see EasyToken
 * @see <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc">Spring Web MVC</a>
 */
public class EasyContext {
    private final EasyCookie cookie;
    private final EasyRequest request;
    private final EasyResponse response;
    private final EasyToken token;

    public EasyContext(final EasyCookie cookie, final EasyRequest request, final EasyResponse response, final EasyToken token) {
        this.cookie = cookie;
        this.request = request;
        this.response = response;
        this.token = token;
    }

    public EasyCookie getCookie() {
        return cookie;
    }

    public EasyRequest getRequest() {
        return request;
    }

    public EasyResponse getResponse() {
        return response;
    }

    public EasyToken getToken() {
        return token;
    }
}
